package org.hxyjs.controller;

import org.hxyjs.dto.DTO;
import org.hxyjs.entity.Bookmaker;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.BookmakerService;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@Controller //@Controller注解是用spring容器生成 对象 默认对象名 bookmakerController
//@RestController //@RequestMapping 用户请求查找该资源使用的名字 网名 默认  /bookmakerController
public class BookmakerController {
	@Resource
    BookmakerService bookmakerService;
	@GetMapping("/Bookmakers")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
    public DTO<Bookmaker> getAllBookmaker() throws Exception{
    	System.out.println("查询全部博彩公司");
    	return bookmakerService.getAllBookmakers();
    }

    @DeleteMapping("/Bookmakers/{bno}")
	@ResponseBody
    public DTO<Bookmaker> deleteBookmakerByBno(@RequestBody @PathVariable("bno") String bno) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
    	System.out.println(bno+"删除博彩公司");
    	return bookmakerService.deleteBookmakerByBno(bno);
    }

	@PostMapping("/Bookmakers")
	@ResponseBody
	public DTO<Bookmaker> addBookmaker(@RequestBody Bookmaker bookmaker) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("增加博彩公司");
		return bookmakerService.addBookmaker(bookmaker);
	}

	@PatchMapping("/Bookmakers")
	@ResponseBody
	public DTO<Bookmaker> updateBookmakerByBno(@RequestBody Bookmaker bookmaker) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("修改博彩公司成功");
		System.out.println(bookmaker);
		return bookmakerService.updateBookmakerByBno(bookmaker);
	}
	@GetMapping("/Bookmakers/{bno}")
	@ResponseBody
	public DTO<Bookmaker> getBookmakerByBno(@PathVariable("bno") String bno) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("查询博彩公司");
		return bookmakerService.getBookmakerByBno(bno);
	}
	@GetMapping("/Bookmakers/pageInfo")
	@ResponseBody
	public DTO<Bookmaker> getBookmakerByPage(@SpringQueryMap PageInfo pageInfo) throws Exception{
		String cacheId = "BookmakerByPage" + pageInfo.getCurrPage();//自编redis每页数据缓存的key
		return pageInfo.getCurrPage() > 2 ? bookmakerService.getBookmakerByPage(pageInfo) :
				bookmakerService.getBookmakerByPage(pageInfo,cacheId);
	}
//	@RequestMapping("/selectBookmakerWithorderAndUser/{bno}")
//	@ResponseBody
//	public DTO<Bookmaker> selectBookmakerWithorderAndUser(@PathVariable("bno")String bno) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
//		System.out.println("查询订单带上用户");
//		return bookmakerService.selectBookmakerWithorderAndUser(bno);
//	}
}
